import logging
from typing import Union

from fastapi import APIRouter, Depends, Request, Header
from fastapi.params import Query
from like.schema_base import PageInationResult
from like.http_base import unified_resp

from like.controller.schemas.system import (SystemLoginIn,DeviceDataIn,DeviceListOut)

from like.controller.service.system.login import ISystemLoginService, SystemLoginService
from like.controller.service.system.auth_admin import ISystemAuthAdminService, SystemAuthAdminService
from like.controller.service.system.auth_menu import ISystemAuthMenuService, SystemAuthMenuService

router = APIRouter(prefix='/system')

@router.post('/login')
@unified_resp
async def login(login_in: SystemLoginIn, login_service: ISystemLoginService = Depends(SystemLoginService.instance)):
    """登录系统"""
    return await login_service.login(login_in)


@router.get('/admin/self')
@unified_resp
async def admin_self(request: Request,
                     auth_service: ISystemAuthAdminService = Depends(SystemAuthAdminService.instance)):
    """管理员信息"""
    return await auth_service.self(request.state.admin_id)


@router.get('/menu/route')
@unified_resp
async def menu_route(request: Request,
                     menu_service: ISystemAuthMenuService = Depends(SystemAuthMenuService.instance)):
    """菜单路由"""
    return await menu_service.select_menu_by_role_id(request.state.role_ids)

@router.get('/device/list',response_model=PageInationResult[DeviceListOut])
@unified_resp
async def login(device_in: DeviceDataIn, login_service: ISystemLoginService = Depends(SystemLoginService.instance)):
    """登录系统"""
    return await login_service.device_list(device_in)